﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DTO;

namespace DAO
{

	public class TblNhomNguoiDungDAO:IData<TblNhomNguoiDung> 
 	{
		public TblNhomNguoiDungDAO(String myconnecString) : base(myconnecString) { }

		protected override int InsertOnSubmit(ref TblNhomNguoiDung item, int t) {
			 return connec.ExecuteNonQuery("sp_TblNhomNguoiDung", CommandType.StoredProcedure,new SqlParameter("@flag", t),
				 new SqlParameter("@" + TblNhomNguoiDung.c_MaNhom, item.MaNhom), new SqlParameter("@" + TblNhomNguoiDung.c_TenNhom, item.TenNhom),
				 new SqlParameter("@" + TblNhomNguoiDung.c_DaXoa, item.DaXoa));
		}

		public override TblNhomNguoiDung GetItem(IDataReader dr)
		{
			TblNhomNguoiDung obj = new TblNhomNguoiDung();
			obj.MaNhom = Convert.ToInt32(dr[TblNhomNguoiDung.c_MaNhom]);
			obj.TenNhom = Convert.ToString(dr[TblNhomNguoiDung.c_TenNhom]);
			obj.DaXoa = Convert.ToBoolean(dr[TblNhomNguoiDung.c_DaXoa]);
			return obj;
		}

		public override List<TblNhomNguoiDung> GetAll()
		{
			return GetAll("sp_GetAllTblNhomNguoiDung", CommandType.StoredProcedure);
		}

		public override TblNhomNguoiDung GetItemById(object id)
		{
			return GetAll().SingleOrDefault(p => p.MaNhom == Convert.ToInt32(id));
		}
		public override TblNhomNguoiDung GetItemById(TblNhomNguoiDung item){
			throw new NotImplementedException();
		}

	}

 }
